package com.study.clothes.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.study.clothes.mapper.OrderMapper;
import com.study.clothes.pojo.Goods;
import com.study.clothes.mapper.GoodsMapper;
import com.study.clothes.service.IGoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Jiayu.Yang
 * @since 2021-12-29
 */
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements IGoodsService {

    @Autowired
    private GoodsMapper goodsMapper;
    @Autowired
    private OrderMapper orderMapper;

    @Override
    public List<Goods> getCars(Integer id) {
        return goodsMapper.getCars(id);
    }

    @Override
    public List<Goods> getCollection() {
        return goodsMapper.getCollection();
    }

    @Override
    public List<Goods> getOrder(Integer id) {
        return goodsMapper.getOrder(id);
    }

    @Override
    public Map<String, Object> page(int page, int size) {
        Page pageInfo=new Page(page,size);
        Page<Goods> iPage = goodsMapper.selectPage(pageInfo, null);
        Map<String, Object> pageMap = new HashMap<>(3);
        pageMap.put("total_record", iPage.getTotal());
        pageMap.put("total_page", iPage.getPages());
        pageMap.put("current_data", iPage.getRecords());

        return pageMap;
    }
}
